﻿using System;
using System.Linq;

namespace NDBGen.Descriptors.Columns.Tokens
{
    [ColumnTokenDescriptor(GeneratesWhenNotPresent = true)]
    public sealed class NullableTokenDescriptor : ColumnTokenDescriptorBase, IOrderedMetadata
    {
        public NullableTokenDescriptor() { }
        internal NullableTokenDescriptor(Boolean isNullable)            
        {
            if (isNullable) this.TokenValue = this.Token.ToString();            
        }

        protected override Char Token { get { return '?'; } }

        public Boolean IsActive
        {
            get { return !String.IsNullOrEmpty(this.TokenValue); }
        }

        #region [ IOrderedMetadata Members ]

        Int32 IOrderedMetadata.GenerationIndex { get { return 0; } }

        #endregion

        public override String ToString()
        {
            if (String.IsNullOrEmpty(this.TokenValue)) return String.Empty;
            return this.Token.ToString();
        }
    }
}